package com.example.srpingsecurityoauth2.pojo;

import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * @ClassName User
 * @Description
 * @Author gqz
 * @Date 2021/12/30 15:42
 * @Version 1.0
 **/
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="User对象", description="")
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class User implements UserDetails {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "用户编号")
    private Long id;

    @ApiModelProperty(value = "用户名")
    private String username;

    @ApiModelProperty(value = "密码")
    private String password;

    @TableField(exist = false)
    private List<GrantedAuthority> authorityList;

    public User(String username, String password, List<GrantedAuthority> authorityList) {
        this.username = username;
        this.password = password;
        this.authorityList = authorityList;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    //当前账户是否过期
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }
    //当前账户是否锁定
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }
    //当前密码是否过期
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }
    //当前账户是否可用
    @Override
    public boolean isEnabled() {
        return true;
    }
}
